#include "Shit.h"

#include "Game.h"


Shit::Shit(Game *game, const char *pathImage, double scaleRate)
	:Object(game, pathImage,scaleRate) 
{
	setType(KindOfObject::kShit);
	frameRateForFallingDown = FRAME_RATE_FOR_FALLING_DOWN;
	lastTimeForMoving = SDL_GetTicks();// Ham Thu Vien 
	setState(States::kStop);
}
void Shit::draw()
{
	switch(currentState)
	{
		case States::kFallDown:
			Object::draw();
			break;
		case States::kStop:
			break;
	}
}

void Shit::update()
{
	double delta = (double)(SDL_GetTicks() - lastTimeForMoving ) / 1000 ;
	double timeLate = 1/ frameRateForFallingDown;
	if (delta >= timeLate)
	{
		switch(currentState)
		{
		case States::kFallDown:
			setSpeed(game->speedForAllofEggs);
			if (rect.sdlRect.y <= SCREEN_HEIGHT)
			{
				moveDown();
				if (checkColision((Object *) game->basket) )
				{
					game->descreaseLives(1);
					setState(States::kStop);
					if (game->basket->life==0) game->setState(Game::States::kGameOver);
				}
			}
			else
				setState(States::kStop);
			break;
		}
		lastTimeForMoving = SDL_GetTicks();
	}
}